<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/10
 * Time: 11:03
 */

namespace app\api\service;

use think\Db;
require_once BASE_ROOT."core/application/common.php";
class UserwapService
{
    /**
 * 检测用户名是否存在
 * @param $appId
 * @return mixed 用户id
 */
    public function checkUsername($user_name,$mch_id)
    {
        $user=Db::name("ybsc_user_wap")->where("user_name",$user_name)->find();
        return $user;
    }
    /**
     * 检测用户名是否存在
     * @param $appId
     * @return mixed 用户id
     */
    public function checkUser($user_name,$password,$mch_id)
    {
        $password=md5($password);
        $user=Db::name("ybsc_user_wap")->where("user_name",$user_name)->where("password",$password)->find();
        if (empty($user)){
            return null;
        }else{
            $userInfo=Db::name("ybsc_user")->where("uid",$user['uid'])->find();

            return $userInfo;
        }
    }
    public function addUser($data)
    {
        $info=Db::name('ybsc_user_share_setting')->where('mch_id',$data['mch_id'])->find();
        if(empty($info) || $info['level']==0){
            $data['pid']=0;
        }
        $rs = Db::name('ybsc_user')->insertGetId($data);
        return $rs;
    }
    /**
 * 添加用户
 * @param $data
 * @return int|string 用户id
 */
    public function addUserwap($data)
    {
        $rs = Db::name('ybsc_user_wap')->insertGetId($data);
        return $rs;
    }
}